dnl Process this file with autoconf to produce a configure script.
AC_INIT(lib/libunshield.h)

AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AM_INIT_AUTOMAKE(unshield, 0.6)
AM_CONFIG_HEADER(lib/unshield_config.h)

CFLAGS="-Wall -Wsign-compare -Wno-long-long $CFLAGS"

case $target in

	powerpc-apple-*)
		dnl Prevent "Undefined Macro argument list" error.
		CFLAGS="-no-cpp-precomp $CFLAGS"
		;;

esac

dnl Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
dnl AM_PATH_CHECK()

dnl Checks for libraries.
AC_LIB_RPATH

dnl Checks for typedefs, structures, and compiler characteristics.
SAVED_CFLAGS="$CFLAGS"
CFLAGS=""
AC_C_CONST
CFLAGS="$SAVED_CFLAGS"

dnl Big-endian stuff
AC_SUBST(WORDS_BIGENDIAN)
AC_SUBST(BYTESWAP_HEADER,dummy)
AC_SUBST(HAVE_BYTESWAP_HEADER,0)

AC_C_BIGENDIAN()

if test "$ac_cv_c_bigendian" = yes; then
  WORDS_BIGENDIAN=1
  AC_CHECK_HEADERS(sys/byteswap.h,[BYTESWAP_HEADER=sys/byteswap.h; HAVE_BYTESWAP_HEADER=1])
  AC_CHECK_HEADERS(byteswap.h,    [BYTESWAP_HEADER=byteswap.h;     HAVE_BYTESWAP_HEADER=1])
else
  WORDS_BIGENDIAN=0
fi

dnl Check where uint16_t and uint32_t may be found
AC_SUBST(INT_HEADER)

dnl Old compilers
AC_CHECK_HEADERS(inttypes.h,[INT_HEADER=inttypes.h])

dnl C99 compliant compilers
AC_CHECK_HEADERS(stdint.h,[INT_HEADER=stdint.h])

if test -z "$INT_HEADER"; then
	AC_MSG_ERROR([Don't know how to get uint16_t and uint32_t on your system])
fi

AC_CHECK_HEADERS(stdbool.h,,[
  AC_MSG_ERROR([Don't know how to get bool values on your system])
])

AC_MSG_CHECKING([for printf format string that works with size_t values])
SAVED_CFLAGS="$CFLAGS"
CFLAGS="-ansi -Wall -Werror"
AC_TRY_COMPILE([#include <stdio.h>],
               [size_t value = 0; printf("%zi", value);],
               [SIZE_FORMAT="zi"],
               [AC_TRY_COMPILE([#include <stdio.h>],
                               [size_t value = 0; printf("%i", value);],
                               [SIZE_FORMAT="i"],
                               [AC_TRY_COMPILE([#include <stdio.h>],
                                               [size_t value = 0; printf("%li", value);],
                                               [SIZE_FORMAT="li"],
                                               [AC_MSG_RESULT([Failed!])
                                                AC_MSG_ERROR([You must be using a really weird platform!])])
                                ])
               ])
AC_MSG_RESULT([${SIZE_FORMAT}])
AC_DEFINE_UNQUOTED(SIZE_FORMAT, 
                   ["${SIZE_FORMAT}"],
                   [printf format that works with size_t values])
CFLAGS="$SAVED_CFLAGS"


# http://www.gnu.org/manual/autoconf-2.53/html_node/AC_LIBOBJ-vs.-LIBOBJS.html
# This is necessary so that .o files in LIBOBJS are also built via
# the ANSI2KNR-filtering rules.
LIB@&t@OBJS=`echo "$LIB@&t@OBJS" | sed 's,\.[[^.]]* ,$U&,g;s,\.[[^.]]*$,$U&,'`
LTLIBOBJS=`echo "$LIB@&t@OBJS" | sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
AC_SUBST(LTLIBOBJS)

CHECK_ZLIB()

CHECK_SSL()
if test x$HAVE_SSL = xyes; then
  USE_OUR_OWN_MD5=0
else
  USE_OUR_OWN_MD5=1
fi
AC_DEFINE_UNQUOTED([USE_OUR_OWN_MD5], [$USE_OUR_OWN_MD5], [Defined if we should use our own MD5 routines.])
AM_CONDITIONAL(USE_OUR_OWN_MD5, [test x$HAVE_SSL != xyes])

AC_OUTPUT([libunshield.pc
           Makefile
           man/Makefile
           lib/md5/Makefile
           lib/Makefile
           src/Makefile])
